import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.LinkedList;

import javax.imageio.ImageIO;


// Project: 

/******************************************************************************
 * <p>
 * File: heroControl.java
 * </p>
 * @author  Tadhg O'Sullivan, rogue
 * @author <a href="mailto:tadhg.osullivan@ucdconnect.ie">tadhg.osullivan@ucdconnect.ie</a>
 * @version 1.0, 2007
 * @created 2-Mar-07 8:01:40 PM
 * @revised 
 * Copyright 2007 Tadhg O'Sullivan
 * <p>
 * Description: assigns coordinates to the hero for movement
 * </p>
 *  
 *  This file is part of Retribution.
 *
 *  Retribution is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Retribution is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Retribution; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *   
 *****************************************************************************/

public class houseMovement {
	protected BufferedImage imgHero = null;
	/**
	 * 
	 * @param h A hero sprite to be moved
	 * @param mt An array filled with map tile to control collision
	 */
	public void moveHero(hero h, mapTile[][] ht, int houseNumber, int prevX, int prevY, int mapHeigth, LinkedList<enemy> el){
		int countKills = 0;
		for(int i=0;i<el.size();i++){
			if(!el.get(i).getLifeState()){
				countKills++;
			}
		}
		switch(countKills){
		case 3:
			h.setHealth(150);
			h.setAttackStrength(2);
			break;
		case 6:
			h.setHealth(200);
			h.setAttackStrength(3);
			break;
		case 9:
			h.setHealth(250);
			h.setAttackStrength(4);
			break;
		case 12:
			h.setHealth(300);
			h.setAttackStrength(5);
			break;
		default:
			h.setHealth(100);
			break;
		}
		System.out.println(countKills++);
		
		String direction = h.getMovement();
		ht[0][4].setCollisionState(true);
		BufferedImage tile2;
		Image scaledImage;
		if(direction.equalsIgnoreCase("down")){
			// check for map collision
			if(((((h.getY())/ (8*(mapHeigth/200))) - 11) == 5) || (ht[((h.getY() + (8*(mapHeigth/200)))/ (8*(mapHeigth/200))) - 11][(h.getX() / (8*(mapHeigth/200))) - 9].collisionState == true)){
				if((((h.getY() / (8*(mapHeigth/200))) - 11) == 5) && (((h.getX()/ (8*(mapHeigth/200))) - 9) == 5)){
					h.setHouse(false);
					h.setX(prevX);
					h.setY(prevY + (8*(mapHeigth/200)));
					h.setMoved();
				}else{
				h.setMoved();
				}
			}else{
				try {
					// get the tileset BufferedImage
				    imgHero = ImageIO.read(this.getClass().getResource("herofr.gif"));
				} catch (IOException e) {
				}
				tile2 = imgHero;
				scaledImage = tile2.getScaledInstance(8*((mapHeigth + (mapHeigth / 2) + ((mapHeigth / 100 ) * 10))/320),8 * (mapHeigth/200), tile2.SCALE_FAST);
				
			h.setImage(scaledImage);
			h.setX(h.getX());
			h.setY((h.getY() + (8*(mapHeigth/200))));
			h.setMoved();
			}
		}
		else if(direction.equalsIgnoreCase("up")){
			// check for map collision
			if(((((h.getY())/ (8*(mapHeigth/200))) - 11) == 0) || (ht[((h.getY() - (8*(mapHeigth/200))) / (8*(mapHeigth/200))) - 11][(h.getX() / (8*(mapHeigth/200))) - 9].collisionState == true)){
				h.setMoved();
			}else{
				try {
					// get the tileset BufferedImage
				    imgHero = ImageIO.read(this.getClass().getResource("herobk.gif"));
				} catch (IOException e) {
				}
				tile2 = imgHero;
				scaledImage = tile2.getScaledInstance(8*((mapHeigth + (mapHeigth / 2) + ((mapHeigth / 100 ) * 10))/320),8 * (mapHeigth/200), tile2.SCALE_FAST);
				
			h.setImage(scaledImage);
			h.setX(h.getX());
			h.setY((h.getY() - (8*(mapHeigth/200))));
			h.setMoved();
			}
		}
		else if(direction.equalsIgnoreCase("left")){
			// check for map collision
			if((((h.getX() / (8*(mapHeigth/200))) - 9) == 0) || (ht[(h.getY() / (8*(mapHeigth/200))) - 11][((h.getX() - (8*(mapHeigth/200)))/ (8*(mapHeigth/200))) - 9].collisionState == true)){
				h.setMoved();
			}else{
				try {
					// get the tileset BufferedImage
				    imgHero = ImageIO.read(this.getClass().getResource("herolt.gif"));
				} catch (IOException e) {
				}
				tile2 = imgHero;
				scaledImage = tile2.getScaledInstance(8*((mapHeigth + (mapHeigth / 2) + ((mapHeigth / 100 ) * 10))/320),8 * (mapHeigth/200), tile2.SCALE_FAST);
				
			h.setImage(scaledImage);
			h.setX(h.getX() - (8*(mapHeigth/200)));
			h.setY(h.getY());
			h.setMoved();
			}
		}
		else if(direction.equalsIgnoreCase("right")){
			// check for map collision
			if((((h.getX() / (8*(mapHeigth/200))) - 9) == 5) || (ht[(h.getY() / (8*(mapHeigth/200))) - 11][((h.getX() + (8*(mapHeigth/200)))/ (8*(mapHeigth/200))) - 9].collisionState == true)){
				h.setMoved();
			}else{
				try {
					// get the tileset BufferedImage
				    imgHero = ImageIO.read(this.getClass().getResource("herort.gif"));
				} catch (IOException e) {
				}
				tile2 = imgHero;
				scaledImage = tile2.getScaledInstance(8*((mapHeigth + (mapHeigth / 2) + ((mapHeigth / 100 ) * 10))/320),8 * (mapHeigth/200), tile2.SCALE_FAST);
				
			h.setImage(scaledImage);
			h.setX(h.getX() + (8*(mapHeigth/200)));
			h.setY(h.getY());
			h.setMoved();
			}
		}
		
	}

}
